import React from "react"
import {Menu} from "antd"
const { SubMenu } = Menu
const exincludes=["/404","/Login"]
export default function UserMenu(props){
    let {routes}=props
    let {history}=props
    let list=[]
    routes.forEach((item)=>{
        let flag=exincludes.includes(item.path)
        if(!flag){
            list.push(item)
        }
    })
    function RenderMenuList(list,history){
       return list.map((item)=>{
           if(Array.isArray(item.children)){
               return <SubMenu key={item.path} title={item.name} onTitleClick={()=>{history.push(item.path)}} icon={item.icon}>{RenderMenuList(item.children,history)}</SubMenu>
           }else{
               return <Menu.Item key={item.path} onClick={()=>{history.push(item.path)}} icon={item.icon}>{item.name}</Menu.Item>
           }
       })
    }
    return <Menu mode="inline"defaultSelectedKeys={["/"]} defaultOpenKeys={["/"]}  theme="dark">{RenderMenuList(list,history)}</Menu>
}